#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pandas as pd
import pymongo
from config import *
from jiaju.dataPiple import datafilter
import numpy as np
import matplotlib.pyplot as plot
import jieba.analyse
from io import StringIO
import jieba
from utils.GwordClude import *
import os

#指定默认字体
plot.rcParams['font.sans-serif'] = ['SimHei']
plot.rcParams['font.family']='sans-serif'


client=pymongo.MongoClient(MONGO_URL);
db=client["taobao"]
datafilter=datafilter()

#获取数据
def getData():
    queryArgs = {}
    projectionFields = {'_id': False}  # 用字典指定
    result = db["jiaju"].find(queryArgs, projection=projectionFields)
    return result

data=pd.DataFrame(list(getData()))
print(data.head())
data=datafilter.dropnull(data)
print(data.describe())

data=data.sort_values(by="deal",ascending=False)
data=data[data["deal"]>100]


def get_key_word():
    key_words={}
    titles=np.array(data["title"])
    f=StringIO()
    for title in titles:
        f.write(title)


    # result=jieba.analyse.extract_tags(f.getvalue(),topK=10)
    return f.getvalue()



generate_cloud_word(jieba.cut(get_key_word()),"../utils/aaaa.jpg","jiaju.jpg")


def showDeal():
    plot.scatter(data["price"], data["deal"])
    plot.xlabel("价格")
    plot.ylabel("销量")
    plot.title("价格销量分布")
    plot.savefig("fenben.png")
    plot.show()


# showDeal()







# jiaju=jiaju[["deal","price"]].astype(np.int32)





